module.exports = {
  data: {
    //监听数据回调页面数组
    watchHandles: []
  },
  methods: {
    //添加监听方法
    addWatchHandle: function (obj) {
      let isAdd = true;
      for (let i = 0; i < this.watchHandles.length; i++) {
        if (this.watchHandles[i].id == obj.id) {
          isAdd = false;
          break;
        }
      }
      if (isAdd) {
        this.watchHandles.push(obj);
      }
    },
    //执行监听处理方法
    runWatchHandle(data, names) {
      for (let i = 0; i < this.watchHandles.length; i++) {
        //根据name指定分发
        if (!names || (names.length && names.indexOf(this.watchHandles[i].id) != -1)) {
          this.watchHandles[i].callBack(data);
        }
      }
    },
    //移除监听方法
    removeWatchHandle(id) {
      for (let i = 0; i < this.watchHandles.length; i++) {
        if (this.watchHandles[i].id == id) {
          this.watchHandles.splice(i, 1);
          break;
        }
      }
    },
  }
}